package com.demo.Test;

import java.text.SimpleDateFormat;
import java.util.Date;

import net.sf.json.JSONObject;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;

public class ThawingTransfer {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String info = null;
		try {
			HttpClient httpclient = new HttpClient();
			PostMethod post = new PostMethod("http://211.162.68.169/user/ThawingTransfer.tran");//
			post.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
			post.addParameter("MERNO", "00000000000094");
			post.addParameter("ORDNO", "4112100024931");
			post.addParameter("CUSTNO", "00000100000081");
			post.addParameter("PAYACNO", "0000010000008101");
			post.addParameter("TXAMT", "900");
			post.addParameter("TOCUSTNO", "00000100000114");
			post.addParameter("TOPAYACNO", "0000010000011401");
			post.addParameter("PAYPASS", "00000000000094");
				Date currentTime = new Date();
			   SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
			   String dateString = formatter.format(currentTime);
			post.addParameter("ORDTIME", dateString);
			post.addParameter("ORDNOTE", "00000100000081");
			String str = "MERNO=00000000000094&ORDNO=4112100024931&CUSTNO=00000100000081&PAYACNO=0000010000008101&"
				+"TXAMT=900&TOCUSTNO=00000100000114&TOPAYACNO=0000010000011401&ORDTIME="+dateString+"&nqkHwgkRdWy5";
			System.out.println("发送--加密前参数==" + str);
			post.addParameter("SIGNDATA",  TdRaAndCaUtil.HKMD5(str));
			System.out.println("发送--加密后参数==" + TdRaAndCaUtil.HKMD5(str));
			int httpcode = httpclient.executeMethod(post);
			System.out.println("httpcode---->" + httpcode);
			info = new String(post.getResponseBody(), "UTF-8");
			System.out.println("返回信息---->" + info);
			JSONObject jsonObj = JSONObject.fromString(info);
			String MERNO = jsonObj.getString("MERNO");
			String CUSTNO = jsonObj.getString("CUSTNO");
			String PAYACNO = jsonObj.getString("PAYACNO");
			String SIGNDATA = jsonObj.getString("SIGNDATA");
			String RSPCOD = jsonObj.getString("RSPCOD");
			String RSPMSG = jsonObj.getString("RSPMSG");
			System.out.println("RSPCOD==" + RSPCOD);
			System.out.println("返回加密参数==" + SIGNDATA);
			String str2 = "MERNO=" + MERNO + "&CUSTNO=" + CUSTNO+ "&PAYACNO=" + PAYACNO +     "&nqkHwgkRdWy5";
			System.out.println("接收--加密前参数==" + str2);
			System.out.println("接收--加密后参数==" + TdRaAndCaUtil.HKMD5(str2));
			if (TdRaAndCaUtil.HKMD5(str2).equals(SIGNDATA)) {
				System.out.println("转账成功");
			} else {
				System.out.println("转账失败");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
